package mlz.b_file;

import java.io.File;

/*
    相对路径与绝对路径
 */
public class FileDemo03 {
    public static void main(String[] args) {
        //D:\Idea-workspace\workspace_2024_lb\JavaSE_advanced\a.txt
        test01();
        // /D:/Idea-workspace/workspace_2024_lb/JavaSE_advanced/out/production/javase_day08/mlz/b_file/a.txt
        test02();
        // /D:/Idea-workspace/workspace_2024_lb/JavaSE_advanced/out/production/javase_day08/a.txt
        test03();
    }

    public static void test01(){
        File file = new File("a.txt");
        //获取绝对路径
        System.out.println(file.getAbsolutePath());
    }

    public static void test02(){
        String path = FileDemo03.class.getResource("a.txt").getPath();
        //这个文件出现的位置只能在同包下
        System.out.println(path);
    }

    public static void test03(){
        String path = FileDemo03.class.getClassLoader().getResource("a.txt").getPath();
        //文件只能出现在src下
        System.out.println(path);
    }
}










